package be.phl.obstacleapp;

import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

public class CommentFragment extends DialogFragment {

	public static final int SCREENING = 1;
	public static final int SCREENING_ROOM = 2;
	public static final int SCREENING_ITEM = 3;
	private static final String TAG = "CommentFragment";
	public Callbacks mButtonCallback;
	private String content;
	private EditText comment;

	public void setContent(String content) {
		this.content = content;
	}

	/**
	 * A callback interface that returns the button clickevent
	 */
	public interface Callbacks {
		/**
		 * Callback for when an item has been selected.
		 */
		public void onCanceled(String comment);

	}

	public CommentFragment() {
		super();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_comment, container);

		comment = (EditText) view.findViewById(R.id.comment);
		comment.setText(content);

		getDialog().setTitle("Commentaar");
		getDialog().setCancelable(true);
		getDialog().setCanceledOnTouchOutside(true);

		return view;
	}

	@Override
	public void onDetach() {
		super.onDetach();
		try {
			Log.i(TAG, "Dialog dismissed");
			mButtonCallback.onCanceled(comment.getText().toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
